package Dao;

import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.List;

import Entity.Comment;
import OracleHelper.OracleHelper;

public class CommentInformationDao {
	public int addComment(Comment comment) {
		String sql="insert into commentInformation values('"+comment.getCommentID()+"','"+comment.getResourceID()+"','"+comment.getCommentatorID()+"',"
				+ "'"+comment.getTheContent()+"','"+comment.getCommentTime()+"')";
		 return new OracleHelper().executeUpdate(sql);		
		
	}
	
	/*搜索某一课程所对应的所有评论信息*/
	public List<Comment> queryCommentByResourceID(String resourceID){
		List<Comment> clist=new ArrayList<Comment>();
		String sql="select * from commentInformation where resourceID='"+resourceID+"'";
		ResultSet rs=OracleHelper.executeQuery(sql);
		try {
			while(rs.next()) {
				Comment comment=new Comment();
				comment.setCommentID(rs.getString(1));
				comment.setResourceID(rs.getString(2));
				comment.setCommentatorID(rs.getString(3));
				comment.setTheContent(rs.getString(4));
				comment.setCommentTime(rs.getString(5));
				clist.add(comment);
			}
		}catch(Exception ex) {
			ex.printStackTrace();
		}
		return clist;
		
	}
	
	/*获取一共有多少条信息*/
	public int queryRecordCount() {
		String sql = "select count(*) from commentInformation";
		Object obj = new OracleHelper().executeSingleQuery(sql);
		return Integer.parseInt(obj.toString());
	}
	

}
